package com.fengye.school.controller;

import com.fengye.school.model.school.School;
import com.fengye.school.response.ResponsePageResult;
import com.fengye.school.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 学院控制器
 *
 * @author sky
 * @since 2021/4/22 7:37 上午
 */
@RestController
@RequestMapping("/school")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    @PostMapping("/save")
    public School save(@RequestBody School school) {
        return schoolService.save(school);
    }

    @GetMapping("/list")
    public List<School> list() {
        return schoolService.list();
    }

    @GetMapping("/list/select")
    public List<School> listForSelect() {
        return schoolService.list();
    }


    @GetMapping("/list/page")
    public ResponsePageResult<School> listByPage(int page, int limit) {
        return schoolService.listByPage(Math.max((page - 1), 0), limit);
    }

    @DeleteMapping("/delete/all")
    public void deleteAll(Long[] ids){
        Arrays.stream(ids).forEach(System.out::println);
        schoolService.deleteAll(ids);
    }

    @DeleteMapping("/delete/id/{id}")
    public void deleteById(@PathVariable(name = "id", required = true)Long id){
        schoolService.deleteById(id);
    }
}
